using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;

using MyFirstXNAGame.Source.Tiles;
using MyFirstXNAGame.Source.Sprites;
namespace MyFirstXNAGame.Source.Levels
{

    class Level1 : Level
    {
        public Level1()
        {
            tilePaths = new String[2];
            spritePaths = new String[6];
            tileTextures = new Texture2D[2];
            spriteTextures = new Texture2D[6];
            tilePaths[0] = "Content\\Textures\\Tiles\\Green";
            tilePaths[1] = "Content\\Textures\\Tiles\\Black";
            spritePaths[0] = "Content\\Textures\\Sprites\\peach";
            spritePaths[1] = "Content\\Textures\\Sprites\\ship";
            spritePaths[2] = "Content\\Textures\\Sprites\\swirl";
            spritePaths[3] = "Content\\Textures\\Sprites\\samus";
            spritePaths[4] = "Content\\Textures\\Sprites\\brick";
            spritePaths[5] = "Content\\Textures\\Sprites\\dachola";
            xBounds = 250;
            yBounds = 21;
        }

        public override void update(GameTime gameTime)
        {
            scrollBackground();
            playerAvatar.input();
            playerAvatar.update(spriteOrigin.X, spriteOrigin.Y, xBounds * 32, yBounds * 32, gameTime, environment, spriteOrigin);
            foreach (Sprite s in npcs)
            {
                s.update(spriteOrigin.X, spriteOrigin.Y, xBounds * 32, yBounds * 32, gameTime, environment, spriteOrigin);
            }
        }

        public void init()
        {
            map = new Texture2D[xBounds, yBounds];
            for (int i = 0; i < xBounds; i++)
            {
                for (int j = 0; j < yBounds; j++)
                {
                    if (i%2 == 0 && j%2==0 || i%2==1 && j%2==1)
                    {
                        map[i, j] = tileTextures[0];
                    }
                    else
                    {
                        map[i, j] = tileTextures[1];
                    }
                }
            }
            viewFrame = new Tile[26,20];
            for (int i = 0; i < 26; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    viewFrame[i, j] = new Tile();
                }
            }
            npcs = loadNPCS();
            environment = loadEnvironment();

            playerAvatar = new Samus();
            playerAvatar.texture = spriteTextures[3];
        }

        public ArrayList loadEnvironment()
        {
            ArrayList theEnvironment = new ArrayList();

            for (int i = 0; i < 250 * 32; i+=32)
            {
                Sprite brick = new Brick();
                brick.levelOrigin.X = i;
                brick.levelOrigin.Y = 18*32;
                brick.texture = spriteTextures[4];
                theEnvironment.Add(brick);
                brick = new Brick();
                brick.levelOrigin.X = i;
                brick.levelOrigin.Y = 0 * 32;
                brick.texture = spriteTextures[4];
                theEnvironment.Add(brick);
            }
            for (int i = 0; i < 18; i++)
            {
                theEnvironment.Add(defineEnvironmentTile(0, i, 4));
                theEnvironment.Add(defineEnvironmentTile(247, i, 4));
            }
                theEnvironment.Add(defineEnvironmentTile(1, 6, 4));
                theEnvironment.Add(defineEnvironmentTile(1, 7, 4));
                theEnvironment.Add(defineEnvironmentTile(1, 8, 4));
                theEnvironment.Add(defineEnvironmentTile(1, 9, 4));
                theEnvironment.Add(defineEnvironmentTile(1, 10, 4));
                theEnvironment.Add(defineEnvironmentTile(1, 11, 4));
                theEnvironment.Add(defineEnvironmentTile(1, 12, 4));
                theEnvironment.Add(defineEnvironmentTile(1, 13, 4));
                theEnvironment.Add(defineEnvironmentTile(1, 14, 4));
                theEnvironment.Add(defineEnvironmentTile(1, 15, 4));
                theEnvironment.Add(defineEnvironmentTile(1, 16, 4));
                theEnvironment.Add(defineEnvironmentTile(1, 17, 4));

                theEnvironment.Add(defineEnvironmentTile(2, 8, 4));
                theEnvironment.Add(defineEnvironmentTile(2, 9, 4));
                theEnvironment.Add(defineEnvironmentTile(2, 10, 4));
                theEnvironment.Add(defineEnvironmentTile(2, 11, 4));
                theEnvironment.Add(defineEnvironmentTile(2, 12, 4));
                theEnvironment.Add(defineEnvironmentTile(2, 13, 4));
                theEnvironment.Add(defineEnvironmentTile(2, 14, 4));
                theEnvironment.Add(defineEnvironmentTile(2, 15, 4));
                theEnvironment.Add(defineEnvironmentTile(2, 16, 4));
                theEnvironment.Add(defineEnvironmentTile(2, 17, 4));
                theEnvironment.Add(defineEnvironmentTile(3, 8, 4));
                theEnvironment.Add(defineEnvironmentTile(3, 9, 4));
                theEnvironment.Add(defineEnvironmentTile(3, 10, 4));
                theEnvironment.Add(defineEnvironmentTile(3, 11, 4));
                theEnvironment.Add(defineEnvironmentTile(3, 12, 4));
                theEnvironment.Add(defineEnvironmentTile(3, 13, 4));
                theEnvironment.Add(defineEnvironmentTile(3, 14, 4));
                theEnvironment.Add(defineEnvironmentTile(3, 15, 4));
                theEnvironment.Add(defineEnvironmentTile(3, 16, 4));
                theEnvironment.Add(defineEnvironmentTile(3, 17, 4));

                theEnvironment.Add(defineEnvironmentTile(4, 10, 4));
                theEnvironment.Add(defineEnvironmentTile(4, 11, 4));
                theEnvironment.Add(defineEnvironmentTile(4, 12, 4));
                theEnvironment.Add(defineEnvironmentTile(4, 13, 4));
                theEnvironment.Add(defineEnvironmentTile(4, 14, 4));
                theEnvironment.Add(defineEnvironmentTile(4, 15, 4));
                theEnvironment.Add(defineEnvironmentTile(4, 16, 4));
                theEnvironment.Add(defineEnvironmentTile(4, 17, 4));
                theEnvironment.Add(defineEnvironmentTile(5, 10, 4));
                theEnvironment.Add(defineEnvironmentTile(5, 11, 4));
                theEnvironment.Add(defineEnvironmentTile(5, 12, 4));
                theEnvironment.Add(defineEnvironmentTile(5, 13, 4));
                theEnvironment.Add(defineEnvironmentTile(5, 14, 4));
                theEnvironment.Add(defineEnvironmentTile(5, 15, 4));
                theEnvironment.Add(defineEnvironmentTile(5, 16, 4));
                theEnvironment.Add(defineEnvironmentTile(5, 17, 4));

                theEnvironment.Add(defineEnvironmentTile(11, 17, 4));
                theEnvironment.Add(defineEnvironmentTile(12, 17, 4));
                theEnvironment.Add(defineEnvironmentTile(13, 17, 4));
                theEnvironment.Add(defineEnvironmentTile(12, 16, 4));
                theEnvironment.Add(defineEnvironmentTile(12, 15, 4));
                theEnvironment.Add(defineEnvironmentTile(12, 13, 0));

                for (int i = 5; i < 14; i++)
                {
                    theEnvironment.Add(defineEnvironmentTile(20, i, 4));
                    theEnvironment.Add(defineEnvironmentTile(26, i, 4));
                }

                theEnvironment.Add(defineEnvironmentTile(21, 17, 4));
                theEnvironment.Add(defineEnvironmentTile(22, 17, 4));
                theEnvironment.Add(defineEnvironmentTile(23, 17, 4));
                theEnvironment.Add(defineEnvironmentTile(24, 17, 4));
                theEnvironment.Add(defineEnvironmentTile(25, 17, 4));

                for (int i = 40; i < 75; i++)
                {
                    for (int j = 1; j < 3; j++)
                    {
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                    }
                }
                for (int i = 45; i < 75; i++)
                {
                    for (int j = 3; j < 6; j++)
                    {
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                    }
                }
                for (int i = 50; i < 75; i++)
                {
                    for (int j = 6; j < 9; j++)
                    {
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                    }
                }
                for (int i = 55; i < 75; i++)
                {
                    for (int j = 9; j < 12; j++)
                    {
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                    }
                }
                for (int i = 60; i < 75; i++)
                {
                    for (int j = 12; j < 15; j++)
                    {
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                    }
                }

                for (int i = 90; i < 115; i++)
                {
                    for (int j = 10; j < 17; j++)
                    {
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                    }
                }

                for (int i = 120; i < 125; i++)
                {
                    theEnvironment.Add(defineEnvironmentTile(i, 9, 4));
                }
                for (int i = 125; i < 130; i++)
                {
                    theEnvironment.Add(defineEnvironmentTile(i, 8, 4));
                }
                for (int i = 140; i < 143; i++)
                {
                    for (int j = 8; j < 18; j++)
                    {
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                    }
                }
                for (int j = 10; j < 18; j++)
                {
                    theEnvironment.Add(defineEnvironmentTile(143, j, 4));
                    theEnvironment.Add(defineEnvironmentTile(144, j, 4));
                }

                for (int i = 160; i < 180; i++)
                {
                    for (int j = 1; j < 6; j++)
                    {
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                    }
                    for (int j = 10; j < 18; j++)
                    {
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                    }
                }

                for (int i = 180; i < 205; i++)
                {
                    for (int j = 14; j < 18; j++)
                    {
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                    }
                }
                for (int i = 183; i < 202; i++)
                {
                    theEnvironment.Add(defineEnvironmentTile(i, 11, 4));
                    theEnvironment.Add(defineEnvironmentTile(i, 14, 4));
                }

                for (int i = 205; i < 240; i++)
                {
                    for (int j = 1; j < 6; j++)
                    {
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                    }
                    for (int j = 10; j < 18; j++)
                    {
                        theEnvironment.Add(defineEnvironmentTile(i, j, 4));
                    }
                }
           
            return theEnvironment;
        }
        public ArrayList loadNPCS()
        {
            ArrayList theNPCS = new ArrayList();
            Sprite s = new Dachola();
            s.texture = spriteTextures[5];
            theNPCS.Add(s);
            return theNPCS;
        }
    }
}
